package com.me.mygdxgame.renderer;

import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;

public class TextureManager
{
	private static TextureManager instance = null;
	
	Map<String, String> textures = new HashMap<String, String>();
	
	private TextureManager()
	{
		
	}
	
	public static TextureManager getInstance()
	{
		if(instance == null)
		{
			instance = new TextureManager();
		}
		
		return instance;
	}
	
	public void addTexture(String name, String path)
	{
		if(textures.containsValue(path))
		{
			Gdx.app.log("TextureManager", path + " has already been loaded");
			return;
		}
		
		textures.put(name, path);
		AssetsManager.getInstance().load(path, Texture.class);
		AssetsManager.getInstance().finishLoading();
	}
	
	public Texture getTexture(String name)
	{
		if(textures.containsKey(name))
		{
			return AssetsManager.getInstance().get(textures.get(name), Texture.class);
		}
		else
		{
			throw new RuntimeException("Could not find texture");
		}
	}
}
